package com.eshore.norm.pattern.combination;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

/**
 * 子菜单，下级可以有子菜单和菜单项
 *
 * @author: v-chenjl62
 * @date: 2024/2/5 17:42
 */
public class Menu extends MenuComponent{

    public Menu(String name,int level) {
        this.name=name;
        this.level=level;
    }

    List<MenuComponent> components = new ArrayList<>();

    @Override
    public void add(MenuComponent component) {
        components.add(component);
    }

    @Override
    public void remove(MenuComponent component) {
        components.remove(component);
    }

    @Override
    public void getChild(int index) {
        components.get(index);
    }

    @Override
    public void print() {
        for (int i = 0; i < this.level; i++) {
            System.out.print("--");
        }
        System.out.println(this.getName());
        //下级也打印
        for (MenuComponent component : components) {
            component.print();
        }
    }
}
